package com.sunday.eight.sort;

/**
 * @author mac
 */
public class QuickSort {
	public static void quickSort(int[] arr, int low, int high) {
		int i, j, temp, t;
		if (low > high) {
			return;
		}
		i = low;
		j = high;
		temp = arr[low];
		while (i < j) {
			while (i < j && arr[j] >= temp) {
				j--;
			}
			while (i < j && arr[i] <= temp) {
				i++;
			}
			if (i < j) {
				t = arr[j];
				arr[j] = arr[i];
				arr[i] = t;
			}
			
			arr[low] = arr[i];
			arr[i] = temp;
			
			quickSort(arr, low, i - 1);
			quickSort(arr, i + 1, high);
		}
	}
	
	public static void main(String[] args) {
		int[] arr = {10, 7, 2, 4, 7, 62, 3, 4, 2, 1, 8, 9, 19};
		quickSort(arr, 0, arr.length - 1);
		for (int i = 0; i < arr.length; i++) {
			System.out.println(arr[i]);
		}
		
	}
	
}
